# 08-随堂练习.py

'''
name,date,money,type,remarks
周杰轮,2022-01-01,100000,消费,正式
周杰轮,2022-01-02,300000,收入,正式
周杰轮,2022-01-03,100000,消费,测试
林俊节,2022-01-01,300000,收入,正式
林俊节,2022-01-02,100000,消费,测试
林俊节,2022-01-03,100000,消费,正式
林俊节,2022-01-04,100000,消费,测试
林俊节,2022-01-05,500000,收入,正式
张学油,2022-01-01,100000,消费,正式
张学油,2022-01-02,500000,收入,正式
张学油,2022-01-03,900000,收入,测试
王力鸿,2022-01-01,500000,消费,正式
王力鸿,2022-01-02,300000,消费,测试
王力鸿,2022-01-03,950000,收入,正式
刘德滑,2022-01-01,300000,消费,测试
刘德滑,2022-01-02,100000,消费,正式
刘德滑,2022-01-03,300000,消费,正式

'''
# 1、读取文件
with open('./09-dehua.txt','r',encoding="utf-8") as file:
# 2、备份一个新文件：dehua.txt.bak
    str = file.read()
with open('./09-dehua.txt.bak','w',encoding="utf-8") as file1:
    file1.write(str)
    file1.flush()
# 3、去除测试 存储为一个新文件
list = []
with open('./09-dehua.txt','r',encoding="utf-8") as file3:
    for x in file3:
        if '测试' not in x:
            list.append(x)

with open('10-dehua.txt','w',encoding="utf-8")as file2:
    file2.writelines(list)